C (61/301)

From:Jesper Svennevid
Date:25 Aug 99 at 16:50:52
Subject:RE: Array limits?

From: "Jesper Svennevid" <jesper@fxrealm.com>

> From: Damir Arh <damir.arh@guest.arnes.si>
>
> Hello,
>
> I just came accross something the other day. I declared a huge array:
>
> char buffer[50000];
>
> Everything was fine when I compiled the program, but nasty bugs
> where occuring all the time, particularly Corrupt Memory List.
> After I reduced the buffer to the size of 5000 everything was
> fine. I'd like to know whether there are really any limits to
> the size of an array.

There might be a stack-overflow problem if you happen to compile
with stack-checking disabled, especially if you use declare such
a large array locally, which will mean that it will be allocated
on function entry and might trash up if your stack is too low..
Some unix-ports may be quite stack-hungry, so if you run with the
default stack you'll probably run in to trouble.

As a general rule, don't allocate variables/arrays larger than
a few kB on the stack, use the proper memory-allocation routines
instead(the clib-routines or pool-allocations to avoid the worst
memory leaks if you happen to forget to free).



// Jesper Svennevid : jesper@fxrealm.com
Software Developer At FXRealm Studios : http://www.fxrealm.com/